Passed
Pull Request — master (#57)
by Salim
19:50
created

sw.js ➔ getDefault   F

Complexity

Conditions 14

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 1
c 0
b 0
f 0
dl 0
loc 1
rs 3.6

How to fix   Complexity   

Complexity

Complex classes like sw.js ➔ getDefault often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/******/ (function(modules) { // webpackBootstrap
2
/******/ 	// The module cache
3
/******/ 	var installedModules = {};
4
/******/
5
/******/ 	// The require function
6
/******/ 	function __webpack_require__(moduleId) {
7
/******/
8
/******/ 		// Check if module is in cache
9
/******/ 		if(installedModules[moduleId]) {
10
/******/ 			return installedModules[moduleId].exports;
11
/******/ 		}
12
/******/ 		// Create a new module (and put it into the cache)
13
/******/ 		var module = installedModules[moduleId] = {
14
/******/ 			i: moduleId,
15
/******/ 			l: false,
16
/******/ 			exports: {}
17
/******/ 		};
18
/******/
19
/******/ 		// Execute the module function
20
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21
/******/
22
/******/ 		// Flag the module as loaded
23
/******/ 		module.l = true;
24
/******/
25
/******/ 		// Return the exports of the module
26
/******/ 		return module.exports;
27
/******/ 	}
28
/******/
29
/******/
30
/******/ 	// expose the modules object (__webpack_modules__)
31
/******/ 	__webpack_require__.m = modules;
32
/******/
33
/******/ 	// expose the module cache
34
/******/ 	__webpack_require__.c = installedModules;
35
/******/
36
/******/ 	// define getter function for harmony exports
37
/******/ 	__webpack_require__.d = function(exports, name, getter) {
38
/******/ 		if(!__webpack_require__.o(exports, name)) {
39
/******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
40
/******/ 		}
41
/******/ 	};
42
/******/
43
/******/ 	// define __esModule on exports
44
/******/ 	__webpack_require__.r = function(exports) {
45
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
0 ignored issues
show
Bug introduced by
The variable Symbol seems to be never declared. If this is a global, consider adding a /** global: Symbol */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
46
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
47
/******/ 		}
48
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
49
/******/ 	};
50
/******/
51
/******/ 	// create a fake namespace object
52
/******/ 	// mode & 1: value is a module id, require it
53
/******/ 	// mode & 2: merge all properties of value into the ns
54
/******/ 	// mode & 4: return value when already ns object
55
/******/ 	// mode & 8|1: behave like require
56
/******/ 	__webpack_require__.t = function(value, mode) {
57
/******/ 		if(mode & 1) value = __webpack_require__(value);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
58
/******/ 		if(mode & 8) return value;
0 ignored issues
show
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
59
/******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
60
/******/ 		var ns = Object.create(null);
61
/******/ 		__webpack_require__.r(ns);
62
/******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
63
/******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
0 ignored issues
show
introduced by
You have used a bitwise operator & in a condition. Did you maybe want to use the logical operator &&
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
unused-code introduced by
The call to bind does not seem necessary since the function does not use this. Consider calling it directly.
Loading history...
64
/******/ 		return ns;
65
/******/ 	};
66
/******/
67
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
68
/******/ 	__webpack_require__.n = function(module) {
69
/******/ 		var getter = module && module.__esModule ?
70
/******/ 			function getDefault() { return module['default']; } :
71
/******/ 			function getModuleExports() { return module; };
72
/******/ 		__webpack_require__.d(getter, 'a', getter);
73
/******/ 		return getter;
74
/******/ 	};
75
/******/
76
/******/ 	// Object.prototype.hasOwnProperty.call
77
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
78
/******/
79
/******/ 	// __webpack_public_path__
80
/******/ 	__webpack_require__.p = "/ohif/";
81
/******/
82
/******/
83
/******/ 	// Load entry module and return exports
84
/******/ 	return __webpack_require__(__webpack_require__.s = 0);
85
/******/ })
86
/************************************************************************/
87
/******/ ([
88
/* 0 */
89
/***/ (function(module, exports) {
0 ignored issues
show
Unused Code introduced by
The parameter exports is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter module is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
90
91
// https://developers.google.com/web/tools/workbox/guides/troubleshoot-and-debug
92
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.0.0-beta.1/workbox-sw.js'); // Install newest
93
// https://developers.google.com/web/tools/workbox/modules/workbox-core
94
95
workbox.core.skipWaiting();
0 ignored issues
show
Bug introduced by
The variable workbox seems to be never declared. If this is a global, consider adding a /** global: workbox */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
96
workbox.core.clientsClaim(); // Cache static assets that aren't precached
97
98
workbox.routing.registerRoute(/\.(?:js|css)$/, new workbox.strategies.StaleWhileRevalidate({
99
  cacheName: 'static-resources'
100
})); // Cache the Google Fonts stylesheets with a stale-while-revalidate strategy.
101
102
workbox.routing.registerRoute(/^https:\/\/fonts\.googleapis\.com/, new workbox.strategies.StaleWhileRevalidate({
103
  cacheName: 'google-fonts-stylesheets'
104
})); // Cache the underlying font files with a cache-first strategy for 1 year.
105
106
workbox.routing.registerRoute(/^https:\/\/fonts\.gstatic\.com/, new workbox.strategies.CacheFirst({
107
  cacheName: 'google-fonts-webfonts',
108
  plugins: [new workbox.cacheableResponse.CacheableResponsePlugin({
109
    statuses: [0, 200]
110
  }), new workbox.expiration.ExpirationPlugin({
111
    maxAgeSeconds: 60 * 60 * 24 * 365,
112
    // 1 Year
113
    maxEntries: 30
114
  })]
115
})); // MESSAGE HANDLER
116
117
self.addEventListener('message', function (event) {
0 ignored issues
show
Bug introduced by
The variable self seems to be never declared. If this is a global, consider adding a /** global: self */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
118
  if (event.data && event.data.type === 'SKIP_WAITING') {
119
    switch (event.data.type) {
120
      case 'SKIP_WAITING':
121
        // TODO: We'll eventually want this to be user prompted
122
        // workbox.core.skipWaiting();
123
        // workbox.core.clientsClaim();
124
        // TODO: Global notification to indicate incoming reload
125
        break;
126
127
      default:
128
        console.warn("SW: Invalid message type: ".concat(event.data.type));
129
    }
130
  }
131
});
132
workbox.precaching.precacheAndRoute([{"revision":"e3ca557deaf9ccfbfb57985b4e447e42","url":"/ohif/0.bcb85f92d7276787be1e.css"},{"revision":"5bd474e145fe51c28b1f2044ce71653b","url":"/ohif/1.bcb85f92d7276787be1e.css"},{"revision":"37c6b1e97da96446a8c1dfb903184661","url":"/ohif/12.bcb85f92d7276787be1e.css"},{"revision":"437cae12248a9ef26456e49b54408929","url":"/ohif/12.bundle.2984165d3050cb4e5079.js"},{"revision":"58e3e76c9b4dbe2ab76a019fb829a1ae","url":"/ohif/13.bundle.3e5e2f4ae66c93deb75a.js"},{"revision":"2625d1e558407a60e7b9a096615ba423","url":"/ohif/14.bcb85f92d7276787be1e.css"},{"revision":"6cc7547e7d6be61df177125cea054286","url":"/ohif/14.bundle.1cf6125c06ea4f1118bb.js"},{"revision":"5b07d34255730b989d166a07021d26f3","url":"/ohif/15.bundle.a6b6b23fccdae51992c5.js"},{"revision":"79c8feb506e92e3cd33a829720e91d2b","url":"/ohif/16.bundle.1535733bbe154b9801db.js"},{"revision":"d91ab7a7cfa7be5e06e572844808c11b","url":"/ohif/17.bundle.bc95065f8ba2bf43a86c.js"},{"revision":"0731d3258f53b657979535b290f4c7a3","url":"/ohif/5.bcb85f92d7276787be1e.css"},{"revision":"260f7b0ecd47a2d3473d498bf9653b59","url":"/ohif/6.bcb85f92d7276787be1e.css"},{"revision":"b2c630a06bf0c045a2c751d4b4cde3fa","url":"/ohif/CallbackPage.bundle.2d4145673c8f2481c46f.js"},{"revision":"6953b35e820145639802b376d48336bc","url":"/ohif/ConnectedStandaloneRouting.bundle.f002d62c6eabfcd8ae69.js"},{"revision":"2f5071227af77d3084727332cba75719","url":"/ohif/ConnectedStandaloneRouting~IHEInvokeImageDisplay~StudyListRouting~ViewerLocalFileData~ViewerRouting.bundle.172f0276ace89850e428.js"},{"revision":"867ec2c4a2d951d4ad4027e0f9f2177b","url":"/ohif/ConnectedStandaloneRouting~IHEInvokeImageDisplay~ViewerLocalFileData~ViewerRouting.bundle.20390ac5d6aa23f33d41.js"},{"revision":"6588ab12bcc028abd9a394481b7e9e50","url":"/ohif/IHEInvokeImageDisplay.bundle.86fc842c87fc3cbe3e8a.js"},{"revision":"a47ea92e1fd326637dcc1b9441564d8e","url":"/ohif/StudyListRouting.bundle.941dbaffb0e233e4c58b.js"},{"revision":"027e43e95134bb3145d41057e02669a7","url":"/ohif/ViewerLocalFileData.bundle.2ffc61b02a58172b9d2a.js"},{"revision":"8dc1b4763c9f92c4d06c9dad15958d02","url":"/ohif/ViewerRouting.bundle.2c20e154c0b3cc130847.js"},{"revision":"ad4a38db8e5ec877a676b33fe3c16b17","url":"/ohif/app-config.js"},{"revision":"cf18697b1e32256a27f97c2db6d2b425","url":"/ohif/app.bcb85f92d7276787be1e.css"},{"revision":"473e74a795f5a95dcfba304960bbcdf8","url":"/ohif/assets/Button_File.svg"},{"revision":"271da60b435c1445580caab72e656818","url":"/ohif/assets/Button_Folder.svg"},{"revision":"cb4f64534cdf8dd88f1d7219d44490db","url":"/ohif/assets/android-chrome-144x144.png"},{"revision":"5cde390de8a619ebe55a669d2ac3effd","url":"/ohif/assets/android-chrome-192x192.png"},{"revision":"e7466a67e90471de05401e53b8fe20be","url":"/ohif/assets/android-chrome-256x256.png"},{"revision":"9bbe9b80156e930d19a4e1725aa9ddae","url":"/ohif/assets/android-chrome-36x36.png"},{"revision":"5698b2ac0c82fe06d84521fc5482df04","url":"/ohif/assets/android-chrome-384x384.png"},{"revision":"56bef3fceec344d9747f8abe9c0bba27","url":"/ohif/assets/android-chrome-48x48.png"},{"revision":"3e8b8a01290992e82c242557417b0596","url":"/ohif/assets/android-chrome-512x512.png"},{"revision":"517925e91e2ce724432d296b687d25e2","url":"/ohif/assets/android-chrome-72x72.png"},{"revision":"4c3289bc690f8519012686888e08da71","url":"/ohif/assets/android-chrome-96x96.png"},{"revision":"cf464289183184df09292f581df0fb4f","url":"/ohif/assets/apple-touch-icon-1024x1024.png"},{"revision":"0857c5282c594e4900e8b31e3bade912","url":"/ohif/assets/apple-touch-icon-114x114.png"},{"revision":"4208f41a28130a67e9392a9dfcee6011","url":"/ohif/assets/apple-touch-icon-120x120.png"},{"revision":"cb4f64534cdf8dd88f1d7219d44490db","url":"/ohif/assets/apple-touch-icon-144x144.png"},{"revision":"977d293982af7e9064ba20806b45cf35","url":"/ohif/assets/apple-touch-icon-152x152.png"},{"revision":"6de91b4d2a30600b410758405cb567b4","url":"/ohif/assets/apple-touch-icon-167x167.png"},{"revision":"87bff140e3773bd7479a620501c4aa5c","url":"/ohif/assets/apple-touch-icon-180x180.png"},{"revision":"647386c34e75f1213830ea9a38913525","url":"/ohif/assets/apple-touch-icon-57x57.png"},{"revision":"0c200fe83953738b330ea431083e7a86","url":"/ohif/assets/apple-touch-icon-60x60.png"},{"revision":"517925e91e2ce724432d296b687d25e2","url":"/ohif/assets/apple-touch-icon-72x72.png"},{"revision":"c9989a807bb18633f6dcf254b5b56124","url":"/ohif/assets/apple-touch-icon-76x76.png"},{"revision":"87bff140e3773bd7479a620501c4aa5c","url":"/ohif/assets/apple-touch-icon-precomposed.png"},{"revision":"87bff140e3773bd7479a620501c4aa5c","url":"/ohif/assets/apple-touch-icon.png"},{"revision":"05fa74ea9c1c0c3931ba96467999081d","url":"/ohif/assets/apple-touch-startup-image-1182x2208.png"},{"revision":"9e2cd03e1e6fd0520eea6846f4278018","url":"/ohif/assets/apple-touch-startup-image-1242x2148.png"},{"revision":"5591e3a1822cbc8439b99c1a40d53425","url":"/ohif/assets/apple-touch-startup-image-1496x2048.png"},{"revision":"337de578c5ca04bd7d2be19d24d83821","url":"/ohif/assets/apple-touch-startup-image-1536x2008.png"},{"revision":"cafb4ab4eafe6ef946bd229a1d88e7de","url":"/ohif/assets/apple-touch-startup-image-320x460.png"},{"revision":"d9bb9e558d729eeac5efb8be8d6111cc","url":"/ohif/assets/apple-touch-startup-image-640x1096.png"},{"revision":"038b5b02bac8b82444bf9a87602ac216","url":"/ohif/assets/apple-touch-startup-image-640x920.png"},{"revision":"2177076eb07b1d64d663d7c03268be00","url":"/ohif/assets/apple-touch-startup-image-748x1024.png"},{"revision":"4fc097443815fe92503584c4bd73c630","url":"/ohif/assets/apple-touch-startup-image-750x1294.png"},{"revision":"2e29914062dce5c5141ab47eea2fc5d9","url":"/ohif/assets/apple-touch-startup-image-768x1004.png"},{"revision":"f692ec286b3a332c17985f4ed38b1076","url":"/ohif/assets/browserconfig.xml"},{"revision":"f3d9a3b647853c45b0e132e4acd0cc4a","url":"/ohif/assets/coast-228x228.png"},{"revision":"533ba1dcac7b716dec835a2fae902860","url":"/ohif/assets/favicon-16x16.png"},{"revision":"783e9edbcc23b8d626357ca7101161e0","url":"/ohif/assets/favicon-32x32.png"},{"revision":"0711f8e60267a1dfc3aaf1e3818e7185","url":"/ohif/assets/favicon.ico"},{"revision":"5df2a5b0cee399ac0bc40af74ba3c2cb","url":"/ohif/assets/firefox_app_128x128.png"},{"revision":"11fd9098c4b07c8a07e1d2a1e309e046","url":"/ohif/assets/firefox_app_512x512.png"},{"revision":"27cddfc922dca3bfa27b4a00fc2f5e36","url":"/ohif/assets/firefox_app_60x60.png"},{"revision":"2017d95fae79dcf34b5a5b52586d4763","url":"/ohif/assets/manifest.webapp"},{"revision":"cb4f64534cdf8dd88f1d7219d44490db","url":"/ohif/assets/mstile-144x144.png"},{"revision":"334895225e16a7777e45d81964725a97","url":"/ohif/assets/mstile-150x150.png"},{"revision":"e295cca4af6ed0365cf7b014d91b0e9d","url":"/ohif/assets/mstile-310x150.png"},{"revision":"cbefa8c42250e5f2443819fe2c69d91e","url":"/ohif/assets/mstile-310x310.png"},{"revision":"aa411a69df2b33a1362fa38d1257fa9d","url":"/ohif/assets/mstile-70x70.png"},{"revision":"5609af4f69e40e33471aee770ea1d802","url":"/ohif/assets/yandex-browser-50x50.png"},{"revision":"cfea70d7ddc8f06f276ea0c85c4b2adf","url":"/ohif/assets/yandex-browser-manifest.json"},{"revision":"0ca44a1b8719e835645ffa804a9d1395","url":"/ohif/es6-shim.min.js"},{"revision":"fc5ca61e7823972f5c8fd43675770bc8","url":"/ohif/google.js"},{"revision":"a980f47e402ab9ede1f3d5f12abedc76","url":"/ohif/index.html"},{"revision":"4e41fd55c08031edf19119a1df1a0538","url":"/ohif/init-service-worker.js"},{"revision":"74fc9658b62903be2048c1f82a22b4d4","url":"/ohif/manifest.json"},{"revision":"754d698a7b334af57c00f29723fd9751","url":"/ohif/oidc-client.min.js"},{"revision":"d05a380d50b74e629738ae6f62fb7e78","url":"/ohif/polyfill.min.js"},{"revision":"f528b6861c82ee4415fce0821fd695c1","url":"/ohif/silent-refresh.html"},{"revision":"909161641aeb7de5df0f6a74d0d06b87","url":"/ohif/vendors~ViewerLocalFileData.bundle.ed3790549719d83b5aef.js"},{"revision":"361ab08d090941c8fda475381e5a9974","url":"/ohif/vendors~dicom-microscopy-viewer.bundle.6325bfb48e0959261062.js"}]); // TODO: Cache API
133
// https://developers.google.com/web/fundamentals/instant-and-offline/web-storage/cache-api
134
// Store DICOMs?
135
// Clear Service Worker cache?
136
// navigator.storage.estimate().then(est => console.log(est)); (2GB?)
137
138
/***/ })
139
/******/ ]);